package cs2114.alarmclock;

import android.view.MotionEvent;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

/**
 * // -------------------------------------------------------------------------
/**
 *  A view that will be used as a background for the application.
 *
 *  @author Joe Acanfora
 *  @version Nov 16, 2011
 */
public class PhotoView extends View
{
    private PhotoLogic photoStream;

    // ----------------------------------------------------------
    /**
     * Creates a new PhotoView.
     *
     * A constructor with these arguments is required for any view that will be
     * added to a layout XML file. Just pass the arguments along to the
     * superclass constructor, and then perform any other initialization after
     * that if you need to.
     *
     * @param context the Context that the view is running in
     * @param attrs the attributes of the XML tag that is inflating the view
     */
    public PhotoView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
    /**
     * Sets the model that will be rendered by this view and
     * also adds the view as aobserver for the model.
     * @param model the model
     */
    public void setModel(PhotoLogic model)
    {
        this.photoStream = model;
        model.addObserver(new PhotoLogic());
    }
    // ----------------------------------------------------------
    /**
     * Called when a touch event occurs on the view; either pressing the finger
     * down for the first time, moving it on the screen, or lifting it back up.
     *
     * @param e a MotionEvent object that describes the touch event
     * @return true if this method handled the touch, or false if it did not
     */
    @Override
    public boolean onTouchEvent(MotionEvent e)
    {
        if (e.getAction() == MotionEvent.ACTION_MOVE)
        {
            //.........
            //.........
            //.........
            //.........
            float xCoord = e.getX();
            float yCoord = e.getY();
            float width = getWidth();
            float height = getHeight();
            // If dragged in the last 10% of right of screen,
            // verticle fifty percent (quarter off top quarter off bottom.)
            if ( (xCoord > .9 * width)
                && (yCoord > .25 * height)
                && (yCoord < .75 * height) )
            {
                photoStream.cyclePhoto();
                postInvalidate();
                return true;
            }

        }
        return false;
    }
}
